package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MeowProducts;
import com.ruoyi.system.service.IMeowProductsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品管理Controller
 * 
 * @author ruoyi
 * @date 2025-06-24
 */
@Controller
@RequestMapping("/system/products")
public class MeowProductsController extends BaseController
{
    private String prefix = "system/products";

    @Autowired
    private IMeowProductsService meowProductsService;

    @RequiresPermissions("system:products:view")
    @GetMapping()
    public String products()
    {
        return prefix + "/products";
    }

    /**
     * 查询商品管理列表
     */
    @RequiresPermissions("system:products:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MeowProducts meowProducts)
    {
        startPage();
        List<MeowProducts> list = meowProductsService.selectMeowProductsList(meowProducts);
        return getDataTable(list);
    }

    /**
     * 导出商品管理列表
     */
    @RequiresPermissions("system:products:export")
    @Log(title = "商品管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MeowProducts meowProducts)
    {
        List<MeowProducts> list = meowProductsService.selectMeowProductsList(meowProducts);
        ExcelUtil<MeowProducts> util = new ExcelUtil<MeowProducts>(MeowProducts.class);
        return util.exportExcel(list, "商品管理数据");
    }

    /**
     * 新增商品管理
     */
    @RequiresPermissions("system:products:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商品管理
     */
    @RequiresPermissions("system:products:add")
    @Log(title = "商品管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MeowProducts meowProducts)
    {
        return toAjax(meowProductsService.insertMeowProducts(meowProducts));
    }

    /**
     * 修改商品管理
     */
    @RequiresPermissions("system:products:edit")
    @GetMapping("/edit/{productId}")
    public String edit(@PathVariable("productId") String productId, ModelMap mmap)
    {
        MeowProducts meowProducts = meowProductsService.selectMeowProductsByProductId(productId);
        mmap.put("meowProducts", meowProducts);
        return prefix + "/edit";
    }

    /**
     * 修改保存商品管理
     */
    @RequiresPermissions("system:products:edit")
    @Log(title = "商品管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MeowProducts meowProducts)
    {
        return toAjax(meowProductsService.updateMeowProducts(meowProducts));
    }

    /**
     * 删除商品管理
     */
    @RequiresPermissions("system:products:remove")
    @Log(title = "商品管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(meowProductsService.deleteMeowProductsByProductIds(ids));
    }
}
